<?php

namespace app\web\controller;
use app\adminmall\model\TemplateModel;
use app\adminmall\model\AgentModel;
use app\common\controller\StoreBaseController;
use think\Db;
/**
 * 行业模板
 */
class TemplateController extends StoreBaseController
{
 	protected $model;
	protected $agentmodel;
	
    protected function _initialize() {
        parent::_initialize();
        $this->model = new TemplateModel();
		$this->agentmodel = new AgentModel();
		$this->assign('ad',$this->model->find());
    }
	
    /**
     * 模板列表
     * @author [longx] 
     */
    public function index($pid='1'){   	
           $dd=Db::table('long_mall_tradetype')->select();
                                                     
    	if($pid=='1'){
    	 $list = $this->model->where('pid',$pid)->paginate(10);	
    	}
    	if($pid=='2'){
    	 $list = $this->model->where('pid',$pid)->paginate(10);	
    	}
    	if($pid=='3'){
    	 $list = $this->model->where('pid',$pid)->paginate(10);	
    	}if($pid=='0'){    	
    	$list=$this->model->paginate(10);
    }
    	$store_id = session('storeInfo')['id'];
        //$list = $this->model->paginate(10);
		$store = db('mall_agent')->where('id',$store_id)->find();
		if(request()->isAjax()){
            $param = input('post.');   
			$param['template_id'] = $param['id']; 			   
         	if ($this->agentmodel->allowField(['template_id'])->save($param,['id' => $store_id]) !== false) {
         			$this->success('设置成功');
            } else {
                $this->error('设置失败');
            }
        }
        
        return $this->fetch('index', ['list' => $list,'tid' => $store['template_id'],'dd'=>$dd]);
    }
 
    	
    	


}